/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package net.saga.lib.asyncserver;

import java.nio.channels.AsynchronousByteChannel;

/**
 *
 * @author summers
 */
public class DefaultConnectionStateFactory implements ConnectionStateFactory {

    public DefaultConnectionStateFactory() {
    }

    @Override
    public  <T extends ConnectionState> T get(Class<T> defaultClazz, AsynchronousByteChannel channel) {
        try {
            T t = defaultClazz.newInstance();
            t.setChannel(channel);
            return t;
        } catch (InstantiationException | IllegalAccessException ex) {
            throw new LoggingIllegalStateException(ex);
        }
    }

    @Override
    public void checkin(ConnectionState state) {
        state.cleanup();
    }
    
    
    
}
